package osSRC.fit_original;
import osSRC.Format;

import java.util.Scanner;

public class Main {
	static Scanner scanner=new Scanner(System.in);
	static String[] modes={"1.request new memory","2.return memory","0.exit"};
	static String length=
			"""
 Please choose whether to accept default memory length:
 0:\t\t\t\t\tdefault("""+Memory.MEMORY_LENGTH+"K)\nAny number else:\tcustom(k)";

	public static void main(String[] args) {
		int collectResult,lengthChoice;
		Memory memory;
		while (true){
			lengthChoice=Format.getInt(length, scanner);
			switch (lengthChoice) {
				case 0:		memory = new Memory();break;
				default:	memory = new Memory(Math.abs(lengthChoice));break;
			}
			System.out.println("Memory initialized");
			break;
		}
		while (true){
			memory.recordFree();
			switch (Format.selectMenu(modes,scanner)) {
				case 1:
					memory.requestAreas();
					break;
				case 2:
					collectResult=memory.collect(
							Format.getInt("Please enter address:",scanner),
							Format.getInt("Please enter length:",scanner)
					);
					if(collectResult!=-1) System.out.println("Space already freed:"+collectResult);
					break;
				case 0:
					System.out.println("Welcome to use again");
					return;
			}
		}
	}
}
